package com.library.admin.listener;

import com.library.admin.AdmLibrary;
import com.library.admin.Menu;
import com.library.admin.form.LoginForm;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;

public class LoginLogoutListener implements ClickListener {
	private static final long serialVersionUID = 1283124532992491755L;
	
	private Menu menu;
	
	public LoginLogoutListener(Menu menu) {
		this.menu = menu;
	}

	public void buttonClick(ClickEvent event) {
		AdmLibrary libraryApplication = (AdmLibrary) menu.getApplication();
		Button loginButton =(Button)event.getSource();
		
		if (loginButton.getCaption().equals("Se connecter")) {
			loginButton.setEnabled(false);
			LoginForm loginForm = new LoginForm();
			menu.addComponent(loginForm, 1);
		}
		else {
			libraryApplication.setConnectedUser(null);
			menu.setDisconnectedMode();
		}
	}
}
